package com.duoketech.service.web.activityorder;
import com.duoketech.config.Constant;
import com.duoketech.model.activity.Activity;
import com.duoketech.model.room.UnitRoom;
import com.duoketech.model.roomorder.RoomOrder;
import com.duoketech.service.AbstractService;
import com.duoketech.model.activityorder.ActivityOrder;
import com.duoketech.exception.ValidateException;
import com.duoketech.utils.search.EqualCondition;
import com.duoketech.utils.search.LikeCondition;
import com.duoketech.utils.search.QueryConstructor;
import com.duoketech.utils.validator.Validator;
import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.Model;
import org.apache.commons.lang3.StringUtils;

public class ActivityOrderService extends AbstractService{
    public static ActivityOrderService ME = new ActivityOrderService();

    @Override
    public void validatorUpdate(Model<?> model, Kv kv) throws ValidateException {
        validatorAdd(model,kv);
    }

    @Override
    public void validatorAdd(Model<?> model, Kv kv) throws ValidateException {

        Validator validator = new Validator();
        validator.excute();

    }

    @Override
    public void beforAdd(Model<?> model, Kv kv) throws ValidateException {

    }

    @Override
    public void afterAdd(Model<?> model, Kv kv) throws ValidateException {

    }

    @Override
    public void beforUpdate(Model<?> model, Kv kv) throws ValidateException {

    }

    @Override
    public void afterUpdate(Model<?> model, Kv kv) throws ValidateException {

    }

    @Override
    public void beforQuery(int id, Model<?> model, Kv kv) throws ValidateException {

    }

    @Override
    public void afterQuery(int id, Model<?> model, Kv kv) throws ValidateException {

    }

    @Override
    public void beforDelete(int id, Model<?> model, Kv kv) throws ValidateException {

    }

    @Override
    public void afterDelete(int id, Model<?> model, Kv kv) throws ValidateException {

    }

    @Override
    public String tableName() {
        return ActivityOrder.dao.tableName();
    }

    @Override
    public void builderSQLExpected(Model<?> model, QueryConstructor queryConstruct, Kv kv) {

        setQuerySQLCommand("select t1.*,t2.name as activityName ");
        queryConstruct.setCommand(" from "+ActivityOrder.dao.tableName()+" t1,"+Activity.dao.tableName() +" t2 where t1.obj_id=t2.id ");
        queryConstruct.setOrderSql("order by t1.id desc");
        queryConstruct.and(new EqualCondition(" and t1.unit_id",kv.getInt(Constant.MEMBER_ID_KEY)));
        String value = model.getStr(ActivityOrder.MOBILE);
        if(StringUtils.isNotEmpty(value)){
            queryConstruct.and(new LikeCondition("t1."+ActivityOrder.MOBILE,"%"+value+"%"));
        }
    }
}